package _01iInetAddress类;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Demo1 {
    public static void main(String[] args) throws UnknownHostException {
        //获取本机的IP地址对象
        InetAddress localHost = InetAddress.getLocalHost();
        //直接打印ip地址对象会打印主机名/IP地址
        System.out.println(localHost);
        //获取获取主机名
        System.out.println("localHost.getHostName() = " + localHost.getHostName());
        //获取IP地址
        System.out.println("localHost.getAddress() = " + localHost.getHostAddress());



        InetAddress baiduAddress = InetAddress.getByName("www.baidu.com");
        System.out.println("baiduAddress = " + baiduAddress);


        InetAddress jdIp = InetAddress.getByName("m.jd.com");
        System.out.println("jdIp.getHostAddress() = " + jdIp.getHostAddress());


    }
}
